$(function () {
	
	//点击导航栏高亮
	$(".daohang ul").on('click',"li",function(){
		$(".daohang ul li button").removeClass("now_p")
		$(this).find("button").addClass("now_p")
		
	})
// 点击导航栏跳转
	$(".daohang>ul").on('click',"li button",function () {
		let $h_his=$(".daohang ul")
		let h_title = $(this).text().trim().replace("×","")
		if(h_title=="首页"){
			document.getElementsByTagName("iframe")[0].setAttribute("src","https://www.sina.com.cn/")
			return
		}
		if(h_title=="帮助中心"){
			document.getElementsByTagName("iframe")[0].setAttribute("src","http://baidu.com")
			return
		}
		clickpage(h_title)
		$('.daohang>ul>li>button').removeClass("now_p")
		$(this).addClass("now_p")
		
	})
// 点击导航栏关闭
	$(".daohang>ul").on("click"," li button a",function () {
		let now_p=$(".daohang .now_p").text().trim().replace("×","")

		if( now_p==undefined||now_p==""||now_p=="首页"){

			document.getElementsByTagName("iframe")[0].setAttribute("src","https://www.sina.com.cn/")
		}
		if(now_p=="帮助中心"){
			document.getElementsByTagName("iframe")[0].setAttribute("src","http://baidu.com")
		}
		if(now_p==$(this).parent().text().trim().replace("×","")){
			let tiitt = $(this).parents("li").prev().text().trim().replace("×","")
			if( tiitt=="首页"){
				document.getElementsByTagName("iframe")[0].setAttribute("src","https://www.sina.com.cn/")

				}
			if(tiitt=="帮助中心"){
				document.getElementsByTagName("iframe")[0].setAttribute("src","http://baidu.com")
			}
			clickpage(tiitt)
		}

		$(this).parents("li").remove()
		return false;
	})

	// 点击页面链接打开页面
	$(".sideMenu ul").on('click',"li a",function () {
		let cnow=$(this).text()
		add_dh(cnow)
		
		})
})


// 打开指定页面
function clickpage(h_title) {
	$.each($(".sideMenu ul li a"),function (i,item) {
		if(item.innerText==h_title){
			$(".sideMenu ul li a")[i].click()
		}
	})
}
function add_dh(cnow) {
	var $li=$('<li><button type="button" class="am-btn am-btn-default am-radius am-btn-xs"></button></li>')
	var flag= false;
	$.each($(".daohang>ul>li>button"),function (i,item) {
		if(item.innerText==cnow+"×"){
			$(".daohang>ul>li>button").removeClass("now_p")
			$(".daohang>ul>li>button")[i].className +=" now_p"
			clickpage(cnow)
			flag =true;
		}
	})
	if(!flag){

		$li.find("button").addClass("now_p")
		$li.find("button").html(cnow+'<a href="javascript: void(0);" target="_self" class="am-close am-close-spin" data-am-modal-close="">×</a>')
		$(".daohang>ul>li>button").removeClass("now_p")
		$(".daohang>ul").append($li)
	
	}
		
}